%::PROVIDES=(
	name	=> ["STOPPING_APP"],
	desc	=> ["Change Application state to STOPPING"],
	type	=> "request",
	code	=> \&::do_handle_stoppingapp
);

sub ::do_handle_stoppingapp {
my $args=shift;
my $app;

	if(!exists($args->{APP})) {
		logwarn("APP_STOPPING request missing APP argument");
		return "MISSING_ARG";
	}

	$app=$args->{APP};
	if(!exists($appmap->{$app})) {
		logwarn("Specified application is not registered");
		return "NOT_REGISTERED";
	}

	$appmap->{$app}->{STATE}="STOPPING";
	$appmap->{$app}->{STARTTIME}=time;
	$h=hostname;
	queue_it("APP_UPDATE app=$app state=STOPPING node=$h");

	#################################################################
	# Send lems a signal to abort if we started it previously.	#
	#################################################################

	if($appmap->{$app}->{MONITOR} && exists($appmap->{$app}->{LEMSPORT})) {
		$lems_client=cld_client->new(INET => "127.0.0.1", KEY => $server_key, PORT => $appmap->{$app}->{LEMSPORT});
		if(!defined($lems_client)) {
			logwarn("Unable to open connection to lems session!");
		} else {
			$lems_response=$lems_client->send_msg(MSG => "ABORT", TIMEOUT => 5);
			$lems_client->close_session;
			#########################################################
			# 0197:	If we do not get a response, do not worry.	#
			#########################################################
			if(defined($lems_response)) {
				logmsg("Response from lems to abort: $lems_response");
			} else {
				logwarn("Lems did not response to abort request -already stopping?");
			}
		}
	}
	return "OK";
}

1;

